package cn.huanzi.qch.baseadmin.travel.scenic.controller;


import cn.huanzi.qch.baseadmin.common.controller.CommonController;
import cn.huanzi.qch.baseadmin.common.pojo.Result;
import cn.huanzi.qch.baseadmin.travel.scenic.pojo.Scenic;
import cn.huanzi.qch.baseadmin.travel.scenic.service.ScenicService;
import cn.huanzi.qch.baseadmin.travel.scenic.vo.ScenicVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 景点管理
 */

@Slf4j
@RestController
@RequestMapping("/travel/scenic")
public class ScenicController extends CommonController<ScenicVo,Scenic,Integer> {

    @Autowired
    private ScenicService scenicService;

    @GetMapping()
    public ModelAndView findAll(ModelAndView modelAndView) {
        List<ScenicVo> scenicList = scenicService.findAll();
        modelAndView.addObject("sciences",scenicList);
        modelAndView.setViewName("travel/front-end/scenic");

        return modelAndView;
    }

    /**
     * 根据id获取景点介绍
     * @param id 前台传入的景点id
     * @param modelAndView 景点介绍
     * @return 页面
     */
    @GetMapping("/detail")
    public ModelAndView findScenicByID(@RequestParam Integer id, ModelAndView modelAndView) {
        Scenic scenic = scenicService.findByScenicID(id);
        modelAndView.addObject("scenicByID", scenic);
        modelAndView.setViewName("travel/front-end/scenicDetail");

        return modelAndView;
    }


//    @Override
//    @PostMapping("/save")
//    public Result<ScenicVo> save(ScenicVo entityVo) {
//        entityVo.setScenicId(1);
//        return super.save(entityVo);
//    }

    @GetMapping("/display")
    public ModelAndView toScenic() {
        return new ModelAndView("travel/scenic/scenic");
    }

    @GetMapping("/add")
    public ModelAndView toAdd() {
        return new ModelAndView("travel/scenic/add");
    }

    @GetMapping("/edit")
    public ModelAndView toEdit(@RequestParam("scenicId") Integer scenicId, ModelAndView modelAndView) {
        Result<ScenicVo> result = scenicService.get(scenicId);
        ScenicVo scenicVo = result.getData();
        modelAndView.addObject("scenic", scenicVo);
        modelAndView.setViewName("travel/scenic/edit");

        return modelAndView;
    }

}